From: Juergen Gross Date: Mon, 28 Aug 2017 07:34:00 +0000 (+0200) Subject: xen/arch/x86/psr.c: let custom parameter parsing routines return errno X-Git-Tag: archive/raspbian/4.11.1-1+rpi1~1^2~66^2~1556 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https:/%22bookmarks:///%22http:/www.example.com/cgi/%22https:/%22bookmarks:/?a=commitdiff_plain;h=0ade5e761d9599e094caa546fecd63c6161e061a;p=xen.git xen/arch/x86/psr.c: let custom parameter parsing routines return errno Modify the custom parameter parsing routines in: xen/arch/x86/psr.c to indicate whether the parameter value was parsed successfully. Signed-off-by: Juergen Gross Acked-by: Jan Beulich --- diff --git a/xen/arch/x86/psr.c b/xen/arch/x86/psr.c index 25a85b65b2..4515100785 100644 --- a/xen/arch/x86/psr.c +++ b/xen/arch/x86/psr.c @@ -418,50 +418,66 @@ static const struct feat_props l2_cat_props = { .write_msr = l2_cat_write_msr, }; -static void __init parse_psr_bool(char *s, char *value, char *feature, +static bool __init parse_psr_bool(const char *s, const char *delim, + const char *ss, const char *feature, unsigned int mask) { - if ( !strcmp(s, feature) ) + if ( !strncmp(s, feature, delim - s) ) { - if ( !value ) + if ( !*delim ) opt_psr |= mask; else { - int val_int = parse_bool(value, NULL); + int val_int = parse_bool(delim + 1, ss); if ( val_int == 0 ) opt_psr &= ~mask; else if ( val_int == 1 ) opt_psr |= mask; + else + return false; } + return true; } + return false; } -static void __init parse_psr_param(char *s) +static int __init parse_psr_param(const char *s) { - char *ss, *val_str; + const char *ss, *val_delim; + const char *q; + int rc = 0; do { ss = strchr(s, ','); - if ( ss ) - *ss = '\0'; - - val_str = strchr(s, ':'); - if ( val_str ) - *val_str++ = '\0'; + if ( !ss ) + ss = strchr(s, '\0'); - parse_psr_bool(s, val_str, "cmt", PSR_CMT); - parse_psr_bool(s, val_str, "cat", PSR_CAT); - parse_psr_bool(s, val_str, "cdp", PSR_CDP); + val_delim = strchr(s, ':'); + if ( !val_delim ) + val_delim = strchr(s, '\0'); - if ( val_str && !strcmp(s, "rmid_max") ) - opt_rmid_max = simple_strtoul(val_str, NULL, 0); - - if ( val_str && !strcmp(s, "cos_max") ) - opt_cos_max = simple_strtoul(val_str, NULL, 0); + if ( *val_delim && !strncmp(s, "rmid_max", val_delim - s) ) + { + opt_rmid_max = simple_strtoul(val_delim + 1, &q, 0); + if ( *q && *q != ',' ) + rc = -EINVAL; + } + else if ( *val_delim && !strncmp(s, "cos_max", val_delim - s) ) + { + opt_cos_max = simple_strtoul(val_delim + 1, &q, 0); + if ( *q && *q != ',' ) + rc = -EINVAL; + } + else if ( !parse_psr_bool(s, val_delim, ss, "cmt", PSR_CMT) && + !parse_psr_bool(s, val_delim, ss, "cat", PSR_CAT) && + !parse_psr_bool(s, val_delim, ss, "cdp", PSR_CDP) ) + rc = -EINVAL; s = ss + 1; - } while ( ss ); + } while ( *ss ); + + return rc; } custom_param("psr", parse_psr_param);